<?php

class sessionHandling{

	const PHOTOS_FROM_FLICKR = "photos_flickr";
	const PHOTOS_FROM_FOLDER = "photos_folder";
	const PHOTOS_FROM_FACEBOOK = "photos_facebook";
	const PHOTOS_FROM_PICASA = "photos_picasa";
	
	const LOGIN = "login";
	private static $localSessionHandler;
	
	private function __construct()
	{
		session_start();
	}
	
	public static function instantiate()
	{
		if(sessionHandling::$localSessionHandler == NULL)
			{sessionHandling::$localSessionHandler = new sessionHandling();}
		return sessionHandling::$localSessionHandler;
	}
	
	/**
	*AUTHENTICATION
	*
	**/
	public function authenticate($login)
	{

		$_SESSION[self::LOGIN] = $login;
	}
	
	public function logout()
	{
		var_dump("test");
		if(isset($_SESSION[self::LOGIN]))
		{
			unset($_SESSION[self::LOGIN]);
		}
	}
	
	public function isAuthenticated()
	{
		if(isset($_SESSION[self::LOGIN]))
		{
			if($_SESSION[self::LOGIN] != "")
			{
				return true;
			}
		}
		return false;
	}
	
	public function addPhotosFromFlickr($title, $urlArray)
	{
		$this->addPhotos(self::PHOTOS_FROM_FLICKR,$title,$urlArray );
	}
	
	public function getPhotosFromFlickr()
	{
		if(isset($_SESSION[self::PHOTOS_FROM_FLICKR]))
		{
			$toReturn = $_SESSION[self::PHOTOS_FROM_FLICKR];
			return $toReturn;
		}else
		{
			return null;
		}
	}
	
	public function addPhotosFromFolder($title, $urlArray)
	{
		$this->addPhotos(self::PHOTOS_FROM_FOLDER,$title,$urlArray );
	}
	
	public function getPhotosFromFolder()
	{
		if(isset($_SESSION[self::PHOTOS_FROM_FOLDER]))
		{
			return $_SESSION[self::PHOTOS_FROM_FOLDER];
		}
		else
		{
			return null;
		}		
	}

	private function addPhotos($repositoryType, $title, $urlArray)
	{
		if(!isset($_SESSION[$repositoryType]))
		{
			$_SESSION[$repositoryType] = array();
		}
		$arrayPhotos = $_SESSION[$repositoryType];
		if(!array_key_exists($title,$arrayPhotos))
		{
			$_SESSION[$repositoryType][$title] = $urlArray;
			return true;
		}else
		{
			return false;
		}
	}
}
?>